package com.example.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.myapplication.R;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    TextView Result;
    EditText txt1;
    EditText txt2;
    Button btn;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setViews();
    }
    public void setViews() {
        txt1 = (EditText)findViewById(R.id.edX);
        txt2 = (EditText)findViewById(R.id.edY);

        btn = (Button)findViewById(R.id.btn);
        btn.setOnClickListener(this);

    }
    @Override
    public void onClick(View v) {
        double x = Double.parseDouble(txt1.getText().toString());
        double y = Double.parseDouble(txt2.getText().toString());
        double res;
        String str = "BMI:";
        x = x/100;
        res = y / (x*x);
        String str1 = String.format("%.2f",res);
        str = str + str1;
        if(res < 19)
            str += "营养不良";
        else if(res < 24)
            str += "适中";
        else if(res<29)
            str += "超重";
        else if(res<34)
            str += "肥胖";
        else
            str += "严重肥胖";
        Result.setText(str);
    }
}
